package com.atguigu.guli.service.statistics.controller.admin;

import com.atguigu.guli.service.result.R;
import com.atguigu.guli.service.statistics.entity.Daily;
import com.atguigu.guli.service.statistics.fegin.MemberFegin;
import com.atguigu.guli.service.statistics.service.DailyService;
import org.apache.commons.lang3.RandomUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/statistics/daily")
public class AdminDailyController {
    @Autowired
    DailyService dailyService;
    @Autowired
    MemberFegin memberFegin;

    @PostMapping("/genDaily/{date}")  // 查询当天的
    public R genDaily(@PathVariable String date){
        Daily daily = new Daily();
        //远程访问
        R registerNum = memberFegin.getRegisterNum(date);
        daily.setRegisterNum(Integer.parseInt(registerNum.getData().get("count").toString()));

        daily.setCourseNum(RandomUtils.nextInt(1000,2000));
        daily.setDateCalculated(date);
        daily.setVideoViewNum(RandomUtils.nextInt(100,2000));
        daily.setLoginNum(RandomUtils.nextInt(1000,2000));
        dailyService.save(daily);
    return R.ok();
    }

    // 查询区间
    @GetMapping("/getDaily/{begin}/{end}")
    public  R getDaily(@PathVariable String begin , @PathVariable String end){
        List<Daily> dailies = dailyService.getDaily(begin,end);
        return R.ok().data("items", dailies);
    }
}
